import React from 'react';
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom';
import './App.css';
import Sidebar from './components/layout/Sidebar';
import ProjectSidebar from './components/layout/ProjectSidebar';
import Header from './components/layout/Header';
import MainContent from './components/layout/MainContent';
import ProjectsPage from './components/pages/ProjectsPage';
import ProjectGroupsPage from './components/pages/ProjectGroupsPage';
import CreateProjectGroupPage from './components/pages/CreateProjectGroupPage';
import ReleasesPage from './components/pages/ReleasesPage';
import AddVersionPage from './pages/AddVersionPage';
import VersionListPage from './pages/VersionListPage';
import { KeycloakProvider } from './contexts/KeycloakContext';
import PrivateRoute from './components/PrivateRoute';
import LoginPage from './pages/LoginPage';
import LoginSuccessPage from './pages/LoginSuccessPage';
// import LogoutPage from './pages/LogoutPage';
import KeycloakTest from './pages/KeycloakTest';
import VersionDetailPage from './pages/VersionDetailPage';

function App() {
  return (
    <KeycloakProvider>
      <Router>
        <div className="App">
          <Routes>
            <Route path="/login" element={<LoginPage />} />
            <Route path="/login-success" element={<LoginSuccessPage />} />
            {/* <Route path="/logout" element={<LogoutPage />} /> */}
            <Route path="/keycloak-test" element={<KeycloakTest />} />
            
            <Route path="/" element={
              <PrivateRoute>
                <>
                  <Header />
                  <Sidebar />
                  <MainContent />
                </>
              </PrivateRoute>
            } />
            
            <Route path="/project-groups" element={
              <PrivateRoute>
                <>
                  <Header />
                  <ProjectSidebar />
                  <ProjectGroupsPage />
                </>
              </PrivateRoute>
            } />
            
            <Route path="/project-groups/create" element={
              <PrivateRoute>
                <>
                  <Header />
                  <ProjectSidebar />
                  <CreateProjectGroupPage />
                </>
              </PrivateRoute>
            } />
            
            <Route path="/projects" element={
              <PrivateRoute>
                <>
                  <Header />
                  <ProjectSidebar />
                  <ProjectsPage />
                </>
              </PrivateRoute>
            } />
            
            <Route path="/releases" element={
              <PrivateRoute>
                <>
                  <Header />
                  <ProjectSidebar />
                  <ReleasesPage />
                </>
              </PrivateRoute>
            } />
            
            <Route path="/yaml" element={
              <PrivateRoute>
                <>
                  <Header />
                  <ProjectSidebar />
                  <MainContent />
                </>
              </PrivateRoute>
            } />
            
            <Route path="/ingress" element={
              <PrivateRoute>
                <>
                  <Header />
                  <ProjectSidebar />
                  <MainContent />
                </>
              </PrivateRoute>
            } />
            
            <Route path="/settings" element={
              <PrivateRoute>
                <>
                  <Header />
                  <Sidebar />
                  <MainContent />
                </>
              </PrivateRoute>
            } />
            
            <Route path="/project/:projectId/add-version" element={
              <PrivateRoute>
                <>
                  <Header />
                  <ProjectSidebar />
                  <AddVersionPage />
                </>
              </PrivateRoute>
            } />
            
            <Route path="/project/:projectId/versions" element={
              <PrivateRoute>
                <>
                  <Header />
                  <ProjectSidebar />
                  <VersionListPage />
                </>
              </PrivateRoute>
            } />
            
            <Route path="/project/:projectId/version/:versionId" element={
              <PrivateRoute>
                <>
                  <Header />
                  <ProjectSidebar />
                  <VersionDetailPage />
                </>
              </PrivateRoute>
            } />
            
            <Route path="*" element={<Navigate to="/" />} />
          </Routes>
        </div>
      </Router>
    </KeycloakProvider>
  );
}

export default App;
